# Copyright (c) Huawei Technologies Co., Ltd. 2020-2021. All rights reserved.
if("x${CMAKE_CXX_COMPILER}" STREQUAL "x")
    set(CMAKE_CXX_COMPILER g++)
endif()
if("x${CMAKE_C_COMPILER}" STREQUAL "x")
    set(CMAKE_C_COMPILER gcc)
endif()

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall -s")
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall")
set(CAMKE_SKIP_RPATH TRUE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack -pie")
add_compile_options(
    -fstack-protector-all
    -D_FORTIFY_SOURCE=2 -O2
)

# add source files
aux_source_directory(. SRCS)

if("x${SRCS}" STREQUAL "x")
    add_custom_target(${OP_TILING_TARGET}
            COMMAND mkdir -p ${OP_TILING_TARGET_OUT_DIR}
            COMMAND echo "no source to make lib${OP_TILING_TARGET}.so")
    return(0)
endif()

set(LIBRARY_OUTPUT_PATH ${OP_TILING_TARGET_OUT_DIR})

message( STATUS "OP_TILING_TARGET=${OP_TILING_TARGET}")

add_library(${OP_TILING_TARGET} SHARED ${SRCS})
add_dependencies(${OP_TILING_TARGET} json)
target_compile_definitions(${OP_TILING_TARGET} PRIVATE
    ONLY_COMPILE_OPEN_SRC
)

target_include_directories(${OP_TILING_TARGET} PRIVATE
    ${JSON_INCLUDE}
    ${OPS_INCLUDE}
    ${METADEF_INCLUDE}
    ${METADEF_INCLUDE}/common/util
    ${METADEF_INCLUDE}/external
    ${METADEF_INCLUDE}/external/graph
    ${METADEF_INCLUDE}/external/exe_graph
    ${METADEF_INCLUDE}/exe_graph
    ${OPENSDK_DIR}/include/slog
    ${OPENSDK_DIR}/c_sec/include
    ${OPENSDK_DIR}/include/air
    ${OPENSDK_DIR}/include/air/external
    ${OPS_UTILS}
)

target_link_libraries(${OP_TILING_TARGET} ${ASCEND_INC}/../lib64/libgraph.so 
                      ${ASCEND_INC}/../lib64/libregister.so 
                      ${ASCEND_INC}/../lib64/libexe_graph.so)
